from __future__ import annotations

from typing import Dict

from loguru import logger
from pydantic import BaseModel, ValidationError


class BitTable(BaseModel):
    app_token: str = ""
    default_table_id: str = ""
    folder_token: str = ""
    name: str = ""
    url: str = ""

    @staticmethod
    def fromJson(data: Dict) -> "BitTable":
        try:
            return BitTable.model_validate(data)
        except ValidationError:
            logger.error(f"数据格式或内容不合法:{data}")
            return BitTable.EMPTY


BitTable.EMPTY = BitTable(
    app_token="", default_table_id="", folder_token="", name="", url=""
)


class FsTable(BaseModel):
    title: str = ""
    folder_token: str = ""
    url: str = ""
    spreadsheet_token: str = ""

    @staticmethod
    def fromJson(data: Dict) -> "FsTable":
        try:
            return FsTable.model_validate(data)
        except ValidationError:
            logger.error(f"数据格式或内容不合法:{data}")
            return FsTable.EMPTY


FsTable.EMPTY = FsTable(title="", folder_token="", url="", spreadsheet_token="")


class FsSheet(BaseModel):
    title: str = ""
    sheetId: str = ""
    index: int = 0

    @staticmethod
    def fromJson(data: Dict) -> "FsSheet":
        try:
            return FsSheet.model_validate(data)
        except ValidationError:
            logger.error(f"数据格式或内容不合法:{data}")
            return FsSheet.EMPTY


FsSheet.EMPTY = FsSheet(title="", sheetId="", index=0)
